home *** CD-ROM | disk | FTP | other *** search
/ PC go! 2008 April / PCgo 2008-04 (DVD).iso / interface / contents / demoversionen_3846 / 13664 / files / Data1.cab / mmerge.bas < prev    next >
Encoding:
BASIC Source File  |  2001-10-16  |  6.5 KB  |  252 lines

  1. Attribute VB_Name = "mMerge"
  2. '******************************************************************'
  3. '*                                                                *'
  4. '*                      TurboCAD for Windows                      *'
  5. '*                   Copyright (c) 1993 - 2001                    *'
  6. '*             International Microcomputer Software, Inc.         *'
  7. '*                            (IMSI)                              *'
  8. '*                      All rights reserved.                      *'
  9. '*                                                                *'
  10. '******************************************************************'
  11.  
  12. Option Explicit
  13.  
  14. Dim gxLStylesSrc  As LineStyles
  15. Dim gxBStylesSrc  As BrushStyles
  16. Dim gxLyrsSrc     As Layers
  17. Dim gxBlocksSrc   As Blocks
  18. Dim gxDwgSrc As Drawing
  19.  
  20. Dim gxLStylesTrg  As LineStyles
  21. Dim gxBStylesTrg  As BrushStyles
  22. Dim gxLyrsTrg     As Layers
  23. Dim gxBlocksTrg   As Blocks
  24. Dim gxDwgTrg As Drawing
  25.  
  26. Private Function MergeLStyle(gxLStyleSrc As LineStyle) As LineStyle
  27.     Dim strName As String
  28.     Dim varDashes As Variant
  29.     
  30.     Dim gxLStyle As LineStyle
  31.     
  32.     strName = gxLStyleSrc.Name
  33.     On Error GoTo AddLStyle
  34.     Set gxLStyle = gxLStylesTrg.Item(strName)
  35. OK:
  36.     Set MergeLStyle = gxLStyle
  37.     Exit Function
  38. AddLStyle:
  39.     On Error GoTo ErrHandler
  40.     gxLStyleSrc.GetDashes varDashes
  41.     Set gxLStyle = gxLStylesTrg.Add(strName, varDashes)
  42.     GoTo OK
  43. ErrHandler:
  44.     If Err.Description <> "" Then
  45.         MsgBox Err.Description
  46.     End If
  47. End Function
  48.  
  49. Private Function MergeBStyle(gxBStyleSrc As BrushStyle) As BrushStyle
  50.     Dim strName As String
  51.     
  52.     Dim gxBStyle As BrushStyle
  53.     
  54.     strName = gxBStyleSrc.Name
  55.     On Error GoTo AddBStyle
  56.     Set gxBStyle = gxBStylesTrg.Item(strName)
  57. OK:
  58.     Set MergeBStyle = gxBStyle
  59.     Exit Function
  60. AddBStyle:
  61.     On Error GoTo ErrHandler
  62.     ' sorry but it is impossible for now to add brush style with
  63.     ' custom hatch style or patterns or etc
  64.     Set gxBStyle = gxBStylesTrg("SOLID")
  65.     GoTo OK
  66. ErrHandler:
  67.     If Err.Description <> "" Then
  68.         MsgBox Err.Description
  69.     End If
  70. End Function
  71.  
  72. Private Function MergeLayer(gxLyrSrc As Layer) As Layer
  73.     
  74.     Dim strName As String
  75.     Dim gxLStyle As LineStyle
  76.     Dim gxBStyle As BrushStyle
  77.     
  78.     Dim gxLyr As Layer
  79.         
  80.     On Error Resume Next
  81.     Set gxLStyle = MergeLStyle(gxLyrSrc.LineStyle)
  82.     Set gxBStyle = MergeBStyle(gxLyrSrc.BrushStyle)
  83.         
  84.     strName = gxLyrSrc.Name
  85.     On Error GoTo AddLyr
  86.     Set gxLyr = gxLyrsTrg.Item(strName)
  87.     Set gxLyr.LineStyle = gxLStyle
  88.     Set gxLyr.BrushStyle = gxBStyle
  89. OK:
  90.     Set MergeLayer = gxLyr
  91.     Exit Function
  92. AddLyr:
  93.     On Error GoTo ErrHandler
  94.     
  95.     Set gxLyr = gxLyrsTrg.Add(strName _
  96.                              , gxLyrSrc.Visible _
  97.                              , gxLyrSrc.Editable _
  98.                              , gxLyrSrc.Frozen _
  99.                              , gxLyrSrc.Color _
  100.                              , gxLStyle _
  101.                              , gxBStyle _
  102.                              , _
  103.                              , gxLyrSrc.ZOrder)
  104.     
  105.     GoTo OK
  106.  
  107. ErrHandler:
  108.     If Err.Description <> "" Then
  109.         MsgBox Err.Description
  110.     End If
  111.  
  112. End Function
  113.  
  114. Private Function MergeBlock(gxBlkSrc As Block) As Block
  115.  
  116.     Dim gxBlkTrg As Block
  117.     Dim gxVrtAnchor As Vertex
  118.     Dim gxGrSrc As Graphic
  119.     Dim gxGrsSrc As Graphics
  120.     Dim gxGrTrg As Graphic
  121.     Dim strName As String
  122.     
  123.     Dim varX As Variant
  124.     Dim varY As Variant
  125.     Dim varZ As Variant
  126.     
  127.     Dim varTileModeOld As Variant
  128.     
  129.     varX = 0
  130.     varY = 0
  131.     varZ = 0
  132.     
  133.     strName = gxBlkSrc.Name
  134.     On Error GoTo AddBlk1
  135.     Set gxBlkTrg = gxBlocksTrg.Item(strName)
  136. OK:
  137.     Set MergeBlock = gxBlkTrg
  138.     Exit Function
  139.  
  140. AddBlk1:
  141.     varTileModeOld = gxDwgTrg.Properties("TileMode")
  142.     gxDwgTrg.Properties("TileMode") = 1
  143.     
  144.     On Error GoTo AddBlk2
  145.     Set gxVrtAnchor = gxBlkSrc.Anchor
  146.     On Error GoTo ErrHandler
  147.     
  148.     varX = gxVrtAnchor.X
  149.     varY = gxVrtAnchor.Y
  150.     varZ = gxVrtAnchor.Z
  151.     
  152. AddBlk2:
  153.     On Error GoTo ErrHandler
  154.     
  155.     Set gxGrsSrc = gxBlkSrc.Graphics
  156.     Set gxGrSrc = gxGrsSrc
  157.     Set gxGrTrg = gxGrSrc.Duplicate()
  158.     gxDwgTrg.Graphics.AddGraphic gxGrTrg
  159.     
  160.     CorrectGraphic gxGrTrg, gxGrSrc
  161.     
  162.     gxBlocksTrg.Add strName, gxGrTrg, varX, varY, varZ
  163.     gxGrTrg.Delete
  164.     
  165.     gxDwgTrg.Properties("TileMode") = varTileModeOld
  166.     GoTo OK
  167. ErrHandler:
  168.     If Err.Description <> "" Then
  169.         MsgBox Err.Description
  170.     End If
  171.  
  172. End Function
  173.  
  174. Private Sub CorrectGraphic(gxGr As Graphic, gxGrSrc As Graphic)
  175.     
  176.     Dim gxGrChild   As Graphic
  177.     Dim gxGrs       As Graphics
  178.     Dim gxBlk       As Block
  179.     Dim gxLStyle As LineStyle
  180.     Dim gxBStyle As BrushStyle
  181.     Dim gxLyr As Layer
  182.     Dim ind As Long
  183.     
  184.     On Error Resume Next
  185.     
  186.     If (gxGr.Builtin) Then
  187.         ind = 0
  188.         Set gxGrs = gxGr.Graphics
  189.         For Each gxGrChild In gxGrs
  190.             CorrectGraphic gxGrChild, gxGrSrc.Graphics(ind)
  191.             ind = ind + 1
  192.         Next gxGrChild
  193.     End If
  194.  
  195.     Set gxLyr = MergeLayer(gxGrSrc.Layer)
  196.     Set gxLStyle = MergeLStyle(gxGrSrc.LineStyle)
  197.     Set gxBStyle = MergeBStyle(gxGrSrc.BrushStyle)
  198.  
  199.     If (gxGr.TypeByValue = imsiInsert) Then
  200.         Set gxBlk = MergeBlock(gxGrSrc.Block)
  201.         gxGr.Block = gxBlk
  202.     End If
  203.  
  204.     gxGr.Layer = gxLyr
  205.     gxGr.LineStyle = gxLStyle
  206.     gxGr.BrushStyle = gxBStyle
  207.  
  208. End Sub
  209.  
  210. Public Sub MergeGraphic(gxGr As Graphic, gxDwgFrom As Drawing, gxDwgTo As Drawing)
  211.  
  212.     Dim gxGrTrg As Graphic
  213.    
  214.     Set gxDwgSrc = gxDwgFrom
  215.     Set gxDwgTrg = gxDwgTo
  216.     
  217.     On Error GoTo Done
  218.     Set gxLStylesSrc = gxDwgSrc.LineStyles
  219.     Set gxBStylesSrc = gxDwgSrc.BrushStyles
  220.     Set gxLyrsSrc = gxDwgSrc.Layers
  221.     Set gxBlocksSrc = gxDwgSrc.Blocks
  222.  
  223.     Set gxLStylesTrg = gxDwgTrg.LineStyles
  224.     Set gxBStylesTrg = gxDwgTrg.BrushStyles
  225.     Set gxLyrsTrg = gxDwgTrg.Layers
  226.     Set gxBlocksTrg = gxDwgTrg.Blocks
  227.  
  228.     Set gxGrTrg = gxDwgSrc.Graphics.Remove(gxGr.Duplicate().Index)
  229.     gxGrTrg.ID = 0
  230.     gxDwgTrg.Graphics.AddGraphic gxGrTrg
  231.  
  232.     CorrectGraphic gxGrTrg, gxGr
  233.  
  234. Done:
  235.     Set gxLStylesSrc = Nothing
  236.     Set gxBStylesSrc = Nothing
  237.     Set gxLyrsSrc = Nothing
  238.     Set gxBlocksSrc = Nothing
  239.     
  240.     Set gxDwgSrc = Nothing
  241.     
  242.     Set gxLStylesTrg = Nothing
  243.     Set gxBStylesTrg = Nothing
  244.     Set gxLyrsTrg = Nothing
  245.     Set gxBlocksTrg = Nothing
  246.     
  247.     Set gxDwgTrg = Nothing
  248.     
  249.  
  250. End Sub
  251.  
  252.